home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_03_05
/
3n05032a
< prev
next >
Wrap
Text File
|
1992-01-29
|
4KB
|
115 lines
#include <dos.h>
#include "windows.h"
/*
******************************************************************
Title: PIPEWIN.C - Windows Component of Pipe Interface
Author: Thomas W. Olsen
Version: 3.0
Compiler: Microsoft C 6.0
cl /AL /Gsw /W3 /Oas /Zpe /Zi /c pipewin.c
cl /AL /Gsw /W3 /Oas /Zpe /Zi /c pipefunc.c
link /CO /NOD pipewin pipefunc ,,, libw llibcew kernel, pipewin.def
rc pipewin.exe
******************************************************************
*/
void FAR PASCAL CallbackProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam);
long FAR PASCAL WindowProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam);
BOOL PASCAL PipeSetup(void);
BOOL PASCAL PipeRegisterCallback(HWND hWnd, FARPROC lpProcPtr);
BOOL PASCAL PipeUnregisterCallback(void);
int PASCAL WinMain(HANDLE hInst, HANDLE hPrevInst, LPSTR lpCmdLine, int numCmdShow )
{
MSG msg;
HWND hWnd;
HDC hContext;
HANDLE selector = 0;
LPSTR lpBuffer = NULL;
WNDCLASS wc;
/************************* Setup Window ************************/
wc.style = NULL;
wc.lpfnWndProc = WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInst;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "PipeClass";
if (!RegisterClass(&wc))
return(FALSE);
hWnd = CreateWindow( "PipeClass", "Windows / DOS Pipe Example",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, hInst, NULL );
if (!hWnd)
return (FALSE);
ShowWindow( hWnd, numCmdShow );
hContext = GetDC( hWnd ); /* Need Display Context */
/****************** Call Device & Wait for Messages ***************/
if (PipeSetup() == FALSE)
{
lpBuffer = "Cannot Find Pipe.";
TextOut( hContext, 0, 0, lpBuffer, lstrlen(lpBuffer) );
}
else
PipeRegisterCallback(hWnd, CallbackProc); /* Tell Pipe Who to Call */
ReleaseDC( hWnd, hContext ); /* Free Display Context */
UpdateWindow( hWnd );
while (GetMessage(&msg, NULL, NULL, NULL)) /* Typical Message Loop */
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
/***************** Receives Call From Virtual Device Pipe *************/
void FAR PASCAL CallbackProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
{
PostMessage(hWnd, message, wParam, lParam); /* Can Only PostMessage() */
return; /* System State Is Unknown */
}
/**************** Receives Posted Message From CallbackProc() *********/
long FAR PASCAL WindowProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
{
struct rmp
{
int BusyBit;
char Buffer[128];
} far *realModePtr = (struct rmp far *) lParam; /* PMode ptr to RMode String */
HDC hContext;
switch (message)
{
case WM_DESTROY:
PostQuitMessage( NULL );
PipeUnregisterCallback();
break;
case WM_USER:
hContext = GetDC( hWnd ); /* Need Display Context */
TextOut( hContext, 0, 0, realModePtr->Buffer, lstrlen(realModePtr->Buffer) );
realModePtr->BusyBit = FALSE;
ReleaseDC( hWnd, hContext ); /* Free Display Context */
UpdateWindow( hWnd );
break;
default:
return (DefWindowProc(hWnd, message, wParam, lParam));
}
}